package yf.dao;



import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import yf.data.DataProviders;

import javax.print.DocFlavor;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBDPConnection {
    private static final Logger log = LoggerFactory.getLogger(DBDPConnection.class);


    static Connection dPConnection = null; //数据链接 mysql

    //数据池连接，mysql
    public static Connection getDPConnection() throws IOException, ClassNotFoundException, SQLException {
        try (InputStream in = DBDPConnection.class.getResourceAsStream("/db.properties")) {
            Properties properties = new Properties();
            properties.load(in);
            String username = properties.getProperty("username");
            String password = properties.getProperty("password");
            String url = properties.getProperty("url");
            // 加载驱动程序
            Class.forName("com.mysql.jdbc.Driver");
            url = "jdbc:mysql://" + url + "?characterEncoding=gb2312&serverTimezone=UTC";  //ip配置;
            log.info("数据池：" + url + "|" + username + "|" + password);
            dPConnection = DriverManager.getConnection(url, username, password);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return dPConnection;
    }


}
